#!/bin/bash

PATH=/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/usr/sfw/bin:/usr/ucb:/usr/bin/X11
export PATH

LANG=C
export LANG

Host="`hostname`"

real_host=`hostname`
os_version=`/usr/bin/uname -sr`
server_model=`/usr/sbin/prtdiag |grep "System Configuration" |/usr/bin/awk '{print $6, $7, $8}'`
cpu=`/usr/sbin/psrinfo |wc -l | awk '{print $1}'|tr '\n' 'x'; /usr/sbin/psrinfo -v|grep MHz|awk '{print $6}'|sort|uniq; echo "MHz"`
 if [ "$os_version" = "SunOS 5.9" ]; then 
    cpu="$cpu `/usr/sbin/psrinfo -vp | awk '{print $2}'|sort |uniq`"
 else
    cpu="$cpu `/usr/sbin/psrinfo -vp | grep MHz |awk '{print $1}'|sort |uniq`"
 fi	
sn=`/usr/sbin/eeprom |grep ChassisSerialNumber | /usr/bin/awk '{print $3}'`
[ -z "$sn" ] && sn=`/opt/SUNWsneep/bin/sneep -e`

#RAM
raminfo=`/usr/sbin/prtdiag | sed -n '/Memory Configuration/,/====/p'`
ram=`echo "$raminfo" | awk '$4 ~ /MB/ || $4 ~ /GB/ {print $4}'`
[ -z "$ram" ] && ram=`echo "$raminfo" | awk 'NF>1' | awk '$(NF-1) ~ /MB/ || $(NF-1) ~ /GB/ {print $(NF-2) $(NF-1)}'`
if [ ! -z "$ram" ]; then
 ram=`echo "$ram" | sort | uniq -c | awk '{print $1, $2}' | sed 's/ /x/'`
 ram=`echo $ram | sed 's/ /; /g'`
fi

echo -n $real_host:$os_version:$server_model:$cpu:$sn:$ram:

#HDD
NumberOfDisks="`ls -l /dev/dsk | grep "c[0-9]t[0-9]d0s2" | awk '{print $NF}' | sed "s/.*devices//" | sed "s/:c$//" |wc -l`"
while [ $NumberOfDisks -ne 0 ] ; do
	i=$(cat /etc/path_to_inst | grep "$(ls -l /dev/dsk |grep "c[0-9]t[0-9]d0s2"|awk '{print $NF}'|sed "s/.*devices//"|sed "s/:c$//"|sed -n ${NumberOfDisks}p)"|awk '{printf "%s, instance #%s\n", $NF, $(NF-1)}'|sed "s/\"//g")
	prtconf -v | nawk '{if ($0~/ '"$i"'$/) { while ($0!~/'"Hardware properties:"'$/){getline;if ($1~/removable-media/)next}  while (i!=2){getline;if($1~/inquiry-product-id/){getline;Product=substr($0,index($0,"=")+2,length($0)-index($0,"=")-2);i++} if($1~/inquiry-vendor-id/){getline;Vendor=substr($0,index($0,"=")+2,length($0)-index($0,"=")-2);i++} } printf "%s %s\n",Vendor, Product } }'
	NumberOfDisks=`expr $NumberOfDisks - 1`
done | sort|uniq -c|awk '{printf "%sx%s; ",$1,substr($0,index($0,$1)+2,length($0)-index($0,$1)-1)}END{printf "\n"}'
